#ifndef NAVIGATION_TASK_WITH_TIMEOUT_H
#define NAVIGATION_TASK_WITH_TIMEOUT_H

#include "task/sync_task.h"
#include "utils/utils/date_time.h"
#include "robot_pose.h"
#include "utils/utils/date_time.h"

class NavigationTaskWithTimeout: public task::SyncTask
{
public:
    explicit NavigationTaskWithTimeout(const std::string &name)
        : task::SyncTask(name)
    {
    }
    ~NavigationTaskWithTimeout()
    = default;
private:
    bool onStart() override
    {
        EASE_INFO("name: %s, on start", task_name_.c_str());
        auto current = base::utils::DateTime::currentDateTime();
        start_time_ = current.toSecond();
        EASE_INFO("current: %s", current.toString("yyyy-MM-dd hh:mm:ss.zzz").c_str());
        auto timeout = current.addMillSecond(5000);
        EASE_INFO("timeout: %s", timeout.toString("yyyy-MM-dd hh:mm:ss.zzz").c_str());
        startTimeout(1000);
        return true;
    }
    task::TaskStatus onRunning() override
    {
        int64_t now = base::utils::DateTime::currentSecond();
        if (now - start_time_ <= cost_time_)
        {
            startTimeout(1000);
            return task::Running;
        }
        EASE_INFO("name: %s, on running pass", task_name_.c_str());
        EASE_INFO("name: %s, done", task_name_.c_str());
        return task::Success;
    }
    bool onPause() override
    {
        EASE_INFO("name: %s, on pause false", task_name_.c_str());
        return false;
    }
    bool onResume() override
    {
        EASE_INFO("name: %s, on resume", task_name_.c_str());
        return true;
    }
    void onCancel() override
    {
        EASE_INFO("name: %s, on cancel", task_name_.c_str());
    }
    bool onTimeout() override
    {
        EASE_INFO("name: %s, on timeout, %s",
               task_name_.c_str(),
               base::utils::DateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz").c_str());
        return false;
    }

private:
    int cost_time_{5};//s
    int64_t start_time_{};
};

#endif //NAVIGATION_TASK_WITH_TIMEOUT_H
